<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>




    <script>
        var arr = [2, 1, 4, 5, 6, 7]
        //   2 1 4 5 6 7

        //    arr.forEach((item,index)=>{

        //     if(item==7){
        //         arr.splice(index,1)
        //         console.log(arr);
        //         console.log(index,'下标1');
        //         console.log(item,'item1');
        //     }
        //    else if(item==2){
        //         arr.splice(index,1)
        //         console.log(arr);
        //         console.log(index,'下标2');
        //         console.log(item,'item2');
        //     }
        //    else if(item==4){
        //         arr.splice(index,1)
        //         console.log(arr,22);
        //         console.log(index,'下标3');
        //         console.log(item,'item3');
        //     }
        //    else if(item==6){
        //         arr.splice(index,1)
        //         console.log(arr,22);
        //         console.log(index,'下标4');
        //         console.log(item,'item4');
        //     }
        //    })

        for (var i = 0; i < arr.length; i++) {
            arr.forEach((item, index) => {
              console.log(index,2222222222222);
                if (item == 7) {
                    arr.splice(index, 1)
                    console.log(arr);
                    console.log(index, '下标1');
                    console.log(item, 'item1');
                } else if (item == 2) {
                    arr.splice(index, 1)
                    console.log(arr);
                    console.log(index, '下标2');
                    console.log(item, 'item2');
                } else if (item == 4) {
                    arr.splice(index, 1)
                    console.log(arr, 22);
                    console.log(index, '下标3');
                    console.log(item, 'item3');
                } else if (item == 6) {
                    arr.splice(index, 1)
                    console.log(arr, 22);
                    console.log(index, '下标4');
                    console.log(item, 'item4');
                }
            })

        }
    </script>
</body>

</html>